let _ = {
  //判断是否是闰年
  isLeepYear: function (year) {
    return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  },
  //手机号打上马赛克方法
  telMosaic: function (val, start = 3, end = 8) {
    return val.substring(0, start) + "***" + val.substring(end);
  },
  //长文本马赛克方法
  Mosaic: function (val, len = 10) {
    return val.length <= len ? val : val.substring(0, 10) + "...";
  },
  //设置Cookie
  setCookie: function (cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
  },

  //获取Cookie
  getCookie: function (cname) {
    let res = "";
    var ca = document.cookie.split("; ");
    ca.map((r) => {
      return r.split("=");
    }).forEach((r) => {
      if (r[0] === cname) {
        res = r[1];
      }
    });
    return res;
  },
};

//extend()方法，用于给$扩展方法
//该方法只传一个参数时，用于将指定对象里面的方法，给$扩展一份
$.extend({
  //判断是否是闰年
  isLeepYear: function (year) {
    return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  },
  //手机号打上马赛克方法
  telMosaic: function (val, start = 3, end = 8) {
    return val.substring(0, start) + "***" + val.substring(end);
  },
  //长文本马赛克方法
  Mosaic: function (val, len = 10) {
    return val.length <= len ? val : val.substring(0, 10) + "...";
  },
  //过滤对象的Left和Top
  filterLeftAndTop(left, top, maxLeft, maxTop, minLeft = 0, minTop = 0) {
    if (left < minLeft) left = minLeft;
    if (left > maxLeft) left = maxLeft;
    if (top < minTop) top = minTop;
    if (top > maxTop) top = maxTop;
    return {
      left,
      top,
    };
  },
  //补零方法
  repair0(val) {
    return (val + "").length > 1 ? val : "0" + val;
  },
  //返回两个日期的时分秒
  getDateHMS(end, start = new Date()) {
    let ms = end - start; //返回两日期之间的毫秒数
    return this.getHMS(ms);
  },
  //返回时分秒
  getHMS(ms) {
    if (ms < 0) ms = 0;
    let h = this.repair0(Math.floor(ms / 1000 / 3600));
    let m = this.repair0(Math.floor(((ms / 1000) % 3600) / 60));
    let s = this.repair0(Math.floor((ms / 1000) % 60));
    return {
      h,
      m,
      s,
    };
  },
});

//给$的实例扩展方法
$.fn.extend({
  mousewheel: function (move) {
    if (window.onmousewheel === undefined) {
      //当前浏览器是火狐
      //兼容火狐浏览器
      window.addEventListener("DOMMouseScroll", function (e) {
        //调用移动方法
        move(e.detail > 0);
      });
    } else {
      //当前浏览器是chrome
      //兼容chrome浏览器
      window.onmousewheel = function (e) {
        //调用移动方法
        move(e.wheelDelta < 0);
      };
    }
  },
});
